/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.ResultSet;

/**
 *
 * @author tran quoc thinh
 */
public class VeDAO {
    public static int InsertVe(String sql)
    {
        try
        {
            MySQLDataAccessHelper dataaccept = new MySQLDataAccessHelper();
            dataaccept.Open();
            return dataaccept.excecuteUpdate(sql);
        }
        catch(Exception ex)
        {
            return 0;
        }
    }
    
    public static int KiemTraVeTonTai(String sql)
    {
        try
        {
        ResultSet rs;
        MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
        dahp.Open();
        
        rs = dahp.excecuteQuery(sql);
//        int count1 = -1;
//        count1 = rs.getInt("sove");
        int count = -1;
        
        while(rs.next())
        {
            count = rs.getRow();
        }
        
        if(count==-1)
            return 1;            
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());            
        }
        return 0;    
    }
    
    public static ResultSet GheDaDat(int maXC)
    {
        try{
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            dahp.Open();
            String sql = "select * from xuatchieu, ve where xuatchieu.maxc = ve.maxc and ve.maxc = "+maXC;
            rs = dahp.excecuteQuery(sql);        
            return rs;
        }catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return null;
    }
    
    public static int LayMaVe(int maXC, int soGhe)
    {
        try{
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            dahp.Open();
            String sql = "select * from  ve where MaXC = "+maXC+" and SoGhe = "+ soGhe;
            rs = dahp.excecuteQuery(sql); 
            int maVe = 0;
            while(rs.next())
            {
                maVe = rs.getInt("MaVe");
            }
            
            return maVe;
        }catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return 0;
    }
}
